package com.limanyik.family.oss.controller;

import com.limanyik.family.common.entity.BasisUser;
import com.limanyik.family.common.entity.server.oss.dto.DownloadTheFileDto;
import com.limanyik.family.common.entity.server.oss.dto.UploadFileDto;
import com.limanyik.family.common.utils.FamilyHttpRequest;
import com.limanyik.family.common.utils.FamilyHttpResponse;
import com.limanyik.family.common.utils.UserUtil;
import com.limanyik.family.oss.service.BaseUploadService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;


/**
 * 统一上传文件Controller
 */
@RestController
public class BaseUploadController {

    @Resource(name = "baseUploadServiceImpl")
    BaseUploadService baseUploadService;

    @PostMapping("/uploadAliyun")
    public FamilyHttpResponse uploadAliyun(UploadFileDto uploadFileDto, MultipartFile[] files) {
        uploadFileDto.setBasisUser(UserUtil.getAdminUser());
        return baseUploadService.uploadAliyunChannel(uploadFileDto, files[0]);
    }

    @PostMapping("/downloadAliyun")
    public FamilyHttpResponse downloadAliyun(HttpServletResponse response, DownloadTheFileDto downloadTheFileDto) {
        return baseUploadService.downloadAliyunChannel(response, downloadTheFileDto);
    }


}
